home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_05 / 2n05064d < prev    next >
Text File  |  1991-03-25  |  375b  |  23 lines

  1.  
  2. int *binsearch(int x, const int v[], size_t n)
  3.     {
  4.     size_t low = 0;
  5.     size_t high = n;
  6.     int mid;
  7.  
  8.     while (low < high)
  9.         {
  10.         mid = (low + high) / 2;
  11.         if (x < v[mid])
  12.             high = mid;
  13.         else if (x > v[mid])
  14.             low = mid + 1;
  15.         else
  16.             return &v[mid];
  17.         }
  18.     return 0;
  19.     };
  20.  
  21.  
  22.  
  23.